package com.example.ordermealservice.service.impl;

import com.alibaba.excel.EasyExcel;
import com.example.commonutils.R;
import com.example.commonutils.handler.NoqueueException;
import com.example.ordermealservice.entity.OrderClassification;
import com.example.ordermealservice.entity.vo.ExcelData;
import com.example.ordermealservice.listener.CategoryExcelListener;
import com.example.ordermealservice.mapper.OrderClassificationMapper;
import com.example.ordermealservice.service.OrderClassificationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2023-06-13
 */
@Service
public class OrderClassificationServiceImpl extends ServiceImpl<OrderClassificationMapper, OrderClassification> implements OrderClassificationService {

    @Override
    public List<String> getOneSubject() {
        List<String> list = baseMapper.getOneSubject();
        return list;
    }

    @Override
    public List<String> getTwoSubject(String oneSubject) {
        List<String> list = baseMapper.getTwoSubject(oneSubject);
        return list;
    }

    @Override
    public void bulkAddCategory(MultipartFile file,OrderClassificationService classificationService){
        //读取excel中的数据
        try {
            InputStream inputStream = file.getInputStream();
            EasyExcel.read(inputStream, ExcelData.class,new CategoryExcelListener(classificationService)).sheet().doRead();
        } catch (IOException e) {
            e.printStackTrace();
            throw new NoqueueException(20001,"导入分类失败");
        }
    }
}
